public class BinarySearchTree {

static class TreeNode {
public int val;
public TreeNode left;
public TreeNode right;

public TreeNode(int val) {
this.val = val;
}
}

public TreeNode root ;

public void insert(int key) {
    TreeNode node = new TreeNode(key);
    if (root == null) {
        root = node;
    }
    TreeNode cur = root;
    TreeNode parent = null;

    while (cur != null) {
        if (cur.val >= key) {
            parent = cur;
            cur = cur.left;
        }else {
            parent = cur;
            cur = cur.right;
        }
    }
    if (parent.val >= key) {
        parent.left = node;
    }else {
        parent.right = node;
    }
}

public TreeNode search(int val) {
    TreeNode cur = root;
    if (cur == null) return null;
    while (cur != null) {
        if(val > cur.val) {
            cur = cur.right;
        } else if (val < cur.val) {
            cur = cur.left;
        }else {
            return cur;
        }
    }
    return null;
}

public void remove(int key) {



    else {
        TreeNode pt = cur;
        TreeNode t =cur.right;
        if (t.left != null) {
            pt = t;
            t = t.left;
        }
        cur.val = t.val;
        pt.left = t.right;
    }
}

}